/*
 * Name        : HttpEvent.java
 * Classes     : HttpEvent
 * Version     : 1.0
 * Date        : 2013-08-29
 *
 * Copyright 2013 CMCC.  All rights reserved.
 * This material, including documentation and any related computer
 * programs, is protected by copyright controlled by CMCC.  All
 * rights are reserved.  Copying, including reproducing, storing,
 * adapting or translating, any or all of this material requires the
 * prior written consent of CMCC.  This material also contains
 * confidential information which may not be disclosed to others
 * without the prior written consent of CMCC.
 */

package com.xgkj.diyiketang.http;

import java.util.Map;


/**
 * class name HttpEvent.java
 * author renhaibin
 * date 2014-11-24 下午3:05:16
 *
 */
public class HttpEvent {

    /**
     * Http event type
     */
    public enum HttpEventType {
        HTTP_EVENT_SUCCESS,
        HTTP_EVENT_FAILED
    }

    /**
     * Error reason for http error event
     */
    public enum HttpErrorCode {
        HTTP_ERROR_TIMEOUT,
        HTTP_ERROR_RESP_CODE_FAIL,
        HTTP_ERROR_CONNECT_FAIL,
        HTTP_ERROR_GENERAL,
        HTTP_ERROR_UNSPECIFICED
    }

    private HttpEventType mType;
    private HttpErrorCode mErrorCode;
    private int mHttpRespCode;
    private byte[] mHttpData;
    private Map<String, String> mHttpRespHeader;

    /**
     * Constructor for http error event
     *
     * @param type event type
     * @param errorCode error code
     */
    public HttpEvent(HttpEventType type, HttpErrorCode errorCode) {
        this(type, 0, null, null, errorCode);
    }

    /**
     * Constructor for http success event without response data
     *
     * @param type event type
     * @param respCode http response code
     * @param header http response header
     */
    public HttpEvent(HttpEventType type, int respCode, Map<String, String> header) {
        this(type, respCode, header, null, HttpErrorCode.HTTP_ERROR_UNSPECIFICED);
    }

    /**
     * Constructor for http success event with data
     *
     * @param type event type
     * @param respCode http response code
     * @param header http response header
     * @param data http response data
     */
    public HttpEvent(HttpEventType type, int respCode, Map<String, String> header ,byte[] data){
    	this(type, respCode, header, data, HttpErrorCode.HTTP_ERROR_UNSPECIFICED);
    }

    /**
     * Constructor for all type of http event
     *
     * @param type event type
     * @param respCode http response code
     * @param header http response header
     * @param data http response data
     * @param errorCode error code
     */
    public HttpEvent(HttpEventType type, int respCode, Map<String, String> header, byte[] data, HttpErrorCode errorCode) {
        mType = type;
        mHttpRespCode = respCode;
        mHttpRespHeader = header;
        mHttpData = data;
        mErrorCode = errorCode;
    }

    public HttpEventType getType() {
        return mType;
    }

    public HttpErrorCode getErrorCode() {
        return mErrorCode;
    }

    public int getHttpRespCode() {
        return mHttpRespCode;
    }

    public byte[] getHttpData() {
        return mHttpData;
    }

    public Map<String, String> getHttpRespHeader() {
        return mHttpRespHeader;
    }

    void setHttpRespCode(int code) {
        mHttpRespCode = code;
    }

    void setErrorCode(HttpErrorCode code) {
        mErrorCode = code;
    }

    void setHttpData(byte[] data) {
        mHttpData = data;
    }
}
